﻿@inject NavigationManager NavigationManager
<div class="top-row ps-3 navbar navbar-dark">
    <div class="container-fluid">
        <a class="navbar-brand" href="">
            <span class="oi oi-compass"></span>Compass
        </a>
        <!--open icon查询地址:https://www.appstudio.dev/app/OpenIconic.html-->
        <button title="Navigation menu" class="navbar-toggler" @onclick="ToggleNavMenu">
            <span class="navbar-toggler-icon"></span>
        </button>
    </div>
</div>

<div class="@NavMenuCssClass" @onclick="ToggleNavMenu">
    <nav class="flex-column">
        <div class="nav-item px-3">
            <NavLink class="nav-link" href="/false" Match="NavLinkMatch.All">
                <span class="oi oi-home ms-3"></span>项目主页
            </NavLink>
        </div>
        <div class="nav-item px-3">
            <NavLink class="nav-link" href="statistics">
                <span class="oi oi-pie-chart ms-3"></span>项目统计
            </NavLink>
        </div>
        <div class="nav-item px-3">
            <NavLink class="nav-link" href="mainplans">
                <span class="oi oi-calendar ms-3"></span>主计划页
            </NavLink>
        </div>
        <div class="nav-item px-3">
            <NavLink class="nav-link" href="projects">
                <span class="oi oi-list ms-3"></span>项目列表
            </NavLink>
        </div>
        <div class="nav-item px-3">
            <NavLink class="nav-link" href="navinvreport">
                <span class="oi oi-bar-chart ms-3"></span>库存报告
            </NavLink>
        </div>
        <div class="nav-item px-3">
            <NavLink class="nav-link" href="finishgoodscounts">
                <span class="oi oi-grid-three-up ms-3"></span>成品库存
            </NavLink>
        </div>
        <div class="nav-item px-3">
            <NavLink class="nav-link" href="cargoinquiry">
                <span class="oi oi-grid-four-up ms-3"></span>物料库存
            </NavLink>
        </div>
        
        
        <div class="nav-item px-3">
            <NavLink class="nav-link" href="importexportinfos">
                <span class="oi oi-key ms-3"></span>申报要素
            </NavLink>
        </div>
        <div class="nav-item px-3">
            <NavLink class="nav-link" href="categories">
                <span class="oi oi-fork ms-3"></span>模型管理
            </NavLink>
        </div>
        <AuthorizeView Roles="admin">
            <Authorized>
                <div class="nav-item px-3">
                    <NavLink class="nav-link" href="users">
                        <span class="oi oi-people ms-3"></span>用户管理
                    </NavLink>
                </div>
                <div class="nav-item px-3">
                    <NavLink class="nav-link" href="functiontest">
                        <span class="oi oi-bolt ms-3"></span>功能测试
                    </NavLink>
                </div>
            </Authorized>
        </AuthorizeView>
        <div class="nav-item px-3">
            <NavLink class="nav-link" href="help">
                <span class="oi oi-question-mark ms-3"></span>帮助信息
            </NavLink>
        </div>
        <div >
            <button class="btn btn-success ms-3" type="button" @onclick="PlayCircle">
                <span class="oi oi-play-circle me-1"></span>
                @(IsStart ? "关闭循环" : "循环展示")
            </button>
        </div>
    </nav>
</div>

@code {
    private bool collapseNavMenu = true;
    private string? NavMenuCssClass => collapseNavMenu ? "collapse" : null;

    private void ToggleNavMenu()
    {
        collapseNavMenu = !collapseNavMenu;
    }

    #region 循环展示

    public bool IsHome { get; set; } = true;
    public bool IsStart { get; set; }
    System.Threading.Timer timer;
    private void PlayCircle()
    {
        if (!IsStart)
        {
            timer = new System.Threading.Timer(_ =>
            {
                InvokeAsync(CircleNav);
            },null,120000,120000);//120s刷新一次
        }
        else
        {
            timer.Dispose();
        }
        IsStart = !IsStart;
    }
    private void CircleNav()
    {
        NavigationManager.NavigateTo(IsHome ? "statistics" : "/true");
        IsHome = !IsHome;
    }
    #endregion

}
